package com.itheima.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.CarItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CarItemDao extends BaseMapper<CarItem> {
    @Select("select * from caritem where userId = #{userId} and productId = #{productId} and status = 0")
    CarItem selectIsExit(@Param("userId") int userId, @Param("productId") int productId);

    @Select("select * from caritem where userId = #{userId} and status = 0")
    List<CarItem> selectCarItemsByUserId(@Param("userId") int userId);

    @Insert("insert into caritem (userId, productId, sellerId, status, createTime)" +
            "values (#{userId}, #{productId}, #{sellerId}, #{status}, #{createTime})")
    int addCarItem(CarItem carItem);

    @Update("update caritem set status = -1 where id = #{id}")
    int deleteCarItem(@Param("id") int id);

    @Update("UPDATE caritem SET status = #{status} WHERE id = #{id}")
    int updateCarItemStatus(@Param("id") Integer carItemId, @Param("status") Integer status);
}
